import {
  mapGetters
} from 'vuex'
export default {
  onShow() {
    this.addCartLogo()
  },
  methods: {
    //添加购物车徽标
    addCartLogo() {
      if (this.total > 0) {
        uni.setTabBarBadge({
          index: 2,
          text: this.total + ''
        })
      } else {
        uni.hideTabBarRedDot({ //隐藏红点
          index: 2
        })
      }
    }
  },
  computed: {
    ...mapGetters('cart', {
      total: 'total'
    })
  },
  watch: {
    total: {
      handler(newVal) {
        this.addCartLogo()
      },
      immediate: true
    }
  }
}
